home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C# & Game Programming - A…er's Guide (2nd Edition)
/
Buono 2nd Ed.iso
/
Chapter2
/
2.29
/
2.29.cs
next >
Wrap
Text File
|
2004-08-31
|
5KB
|
89 lines
/* Battle Bit II û THIS IS WAR! Some mad dog soldier shot down the
* alien Ambassador's convoy and it sparked an intergalactic war.
* Earth's defenses was weak form warring with several hundred other
* worlds. So now, it's all up to you. */
using System;
namespace Chapter2 {
class Class1 {
static void Main() {
string input;
char cYesNo;
Random rnd = new Random();
do { // do-while loop
double iAlienShip1 = Math.Round (rnd.NextDouble() * 100) + 1,
iAlienShip2 = Math.Round (rnd.NextDouble() * 100) + 1,
iTarget = 0,
iAliensMissiles = 0;
const double iYourLocation = 50;
Console.WriteLine("Captain, are you in there? Captain?\n"
+ "(Crying is herd form his quarters)\n"
+ "This is ground control to lieutenant Bob.\n"
+ "Your brother Major Tom has been shot down,\n"
+ "Repeat he has been shot down.\n"
+ "The aliens have destroyed our space outpost and \n"
+ "are now on route to Earth.\n"
+ "I know it's a long shot Lieutenant,\n"
+ "but I promised my wife and kids you'd stop them.\n"
+ "I'll do my best...\n");
while ((iAlienShip1 > 0) || (iAlienShip2 > 0)) {
Console.Write("\n\n Enter targeting information: ");
input = Console.ReadLine();
iTarget = byte.Parse(input);
Console.WriteLine("{0},{1}", iAlienShip1, iAlienShip2);
if (Math.Ceiling(iTarget) == Math.Ceiling(iAlienShip1)
|| Math.Ceiling(iTarget) == Math.Floor(iAlienShip1)
|| Math.Floor(iTarget) == Math.Ceiling(iAlienShip1)
|| Math.Floor(iTarget) == Math.Floor(iAlienShip1)) {
Console.WriteLine("Alien ship hit, you got him!");
iAlienShip1 = -1;
}
if (Math.Ceiling(iTarget) == Math.Ceiling(iAlienShip2)
|| Math.Ceiling(iTarget) == Math.Floor(iAlienShip2)
|| Math.Floor(iTarget) == Math.Ceiling(iAlienShip2)
|| Math.Floor(iTarget) == Math.Floor(iAlienShip2)) {
Console.WriteLine("\nAlien ship hit, you took him down!!\n");
iAlienShip2 = -1;
}
if ((Math.Round (iTarget) > Math.Round (iAlienShip1))
&& (Math.Round (iTarget) > Math.Round (iAlienShip2)))
Console.WriteLine("\n You missed, try aiming a little lower\n");
else if ((iTarget < iAlienShip1) && (iTarget < iAlienShip2))
Console.WriteLine("\n You missed, try aiming higher\n");
else
Console.WriteLine("\n I can't get a lock on them\n");
if (Math.Ceiling(iAliensMissiles) == Math.Ceiling(iYourLocation)
|| Math.Ceiling(iAliensMissiles) == Math.Floor(iYourLocation)
|| Math.Floor(iAliensMissiles) == Math.Ceiling(iYourLocation)
|| Math.Floor(iAliensMissiles) == Math.Ceiling(iYourLocation))
break;
else
iAliensMissiles = rnd.NextDouble();
} // end loop
if ((iAlienShip1 + iAlienShip2) < 0)
Console.WriteLine("\n Good work lieutenant, "
+ "or should I say captain.\n");
else
Console.WriteLine("\n BOOM!!! You're dead.\n");
Console.WriteLine("\n Game Over\n"
+ "\n Would you like to play again? (Y/N)");
input = Console.ReadLine();
cYesNo = char.Parse(input);
cYesNo = char.ToUpper(cYesNo);
} while (cYesNo == 'Y');
}
}
}